package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IFlowContractService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.FlowContractCreateValidate;
import com.mdd.admin.validate.FlowContractUpdateValidate;
import com.mdd.admin.validate.FlowContractSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.FlowContractListedVo;
import com.mdd.admin.vo.FlowContractDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/flow")
@Api(tags = "新建合同流程记录管理")
public class FlowContractController {

    @Resource
    IFlowContractService iFlowContractService;

    @GetMapping("/list")
    @ApiOperation(value="新建合同流程记录列表")
    public AjaxResult<PageResult<FlowContractListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated FlowContractSearchValidate searchValidate) {
        PageResult<FlowContractListedVo> list = iFlowContractService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="新建合同流程记录详情")
    public AjaxResult<FlowContractDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        FlowContractDetailVo detail = iFlowContractService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "新建合同流程记录新增")
    @PostMapping("/add")
    @ApiOperation(value="新建合同流程记录新增")
    public AjaxResult<Object> add(@Validated @RequestBody FlowContractCreateValidate createValidate) {
        iFlowContractService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "新建合同流程记录编辑")
    @PostMapping("/edit")
    @ApiOperation(value="新建合同流程记录编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody FlowContractUpdateValidate updateValidate) {
        iFlowContractService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "新建合同流程记录删除")
    @PostMapping("/del")
    @ApiOperation(value="新建合同流程记录删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iFlowContractService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
